package com.ruyuan.eshop.data.migrate.tool.canal.binlog.impl;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.otter.canal.protocol.CanalEntry;
import com.ruyuan.eshop.data.migrate.tool.canal.binlog.BinlogConsumer;
import com.ruyuan.eshop.data.migrate.tool.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author zhonghuashishan
 * @version 1.0
 */
@Component
public class BinlogConsumerImpl implements BinlogConsumer {

    @Autowired
    private TargetAfterSaleInfoService targetAfterSaleInfoService;

    @Autowired
    private TargetAfterSaleItemService targetAfterSaleItemService;

    @Autowired
    private TargetAfterSaleLogService targetAfterSaleLogService;

    @Autowired
    private TargetAfterSaleRefundService targetAfterSaleRefundService;

    @Autowired
    private TargetOrderAmountDetailService targetOrderAmountDetailService;

    @Autowired
    private TargetOrderAmountService targetOrderAmountService;

    @Autowired
    private TargetOrderAutoNoService targetOrderAutoNoService;

    @Autowired
    private TargetOrderCancelScheduledTaskService targetOrderCancelScheduledTaskService;

    @Autowired
    private TargetOrderDeliveryDetailService targetOrderDeliveryDetailService;

    @Autowired
    private TargetOrderInfoService targetOrderInfoService;

    @Autowired
    private TargetOrderItemService targetItemService;

    @Autowired
    private TargetOrderPaymentDetailService targetOrderPaymentDetailService;

    @Autowired
    private TargetTendConsistencyTaskService targetTendConsistencyTaskService;

    @Override
    public void consumer(String tableName, CanalEntry.EventType eventType, JSONObject beforeData, JSONObject afterData) {
        if("after_sale_info".equalsIgnoreCase(tableName)) {
            targetAfterSaleInfoService.consumer(eventType, beforeData, afterData);
            return;
        }

        if("after_sale_item".equalsIgnoreCase(tableName)) {
            targetAfterSaleItemService.consumer(eventType, beforeData, afterData);
            return;
        }

        if("after_sale_log".equalsIgnoreCase(tableName)) {
            targetAfterSaleLogService.consumer(eventType, beforeData, afterData);
            return;
        }

        if("after_sale_refund".equalsIgnoreCase(tableName)) {
            targetAfterSaleRefundService.consumer(eventType, beforeData, afterData);
            return;
        }

        if("order_amount_detail".equalsIgnoreCase(tableName)) {
            targetOrderAmountDetailService.consumer(eventType, beforeData, afterData);
            return;
        }

        if("order_amount".equalsIgnoreCase(tableName)) {
            targetOrderAmountService.consumer(eventType, beforeData, afterData);
            return;
        }

        if("order_auto_no".equalsIgnoreCase(tableName)) {
            targetOrderAutoNoService.consumer(eventType, beforeData, afterData);
            return;
        }

        if("order_cancel_scheduled_task".equalsIgnoreCase(tableName)) {
            targetOrderCancelScheduledTaskService.consumer(eventType, beforeData, afterData);
            return;
        }

        if("order_delivery_detail".equalsIgnoreCase(tableName)) {
            targetOrderDeliveryDetailService.consumer(eventType, beforeData, afterData);
            return;
        }

        if("order_info".equalsIgnoreCase(tableName)) {
            targetOrderInfoService.consumer(eventType, beforeData, afterData);
            return;
        }

        if("order_item".equalsIgnoreCase(tableName)) {
            targetItemService.consumer(eventType, beforeData, afterData);
        }

        if("order_payment_detail".equalsIgnoreCase(tableName)) {
            targetOrderPaymentDetailService.consumer(eventType, beforeData, afterData);
        }

        if("ruyuan_tend_consistency_task".equalsIgnoreCase(tableName)) {
            targetTendConsistencyTaskService.consumer(eventType, beforeData, afterData);
        }
    }
}